package com.wzp.yyptproject.until;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.Part;
import java.io.*;
@Slf4j
public class ImgUtil {
    @Autowired
    private FtpOperation ftpOperation;
    public static void inputoutput(Part inputfile, File file) throws IOException{
        InputStream is = inputfile.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);
        // 输出流
        OutputStream os= new FileOutputStream(file);
        BufferedOutputStream bos = new BufferedOutputStream(os);
        //赋值

        byte[] b = new byte[1024];
        int len = 0;
        while ((len=bis.read(b))!=-1){
            bos.write(b,0,len);
        }

        bos.flush();
        bos.close();
        bis.close();
        os.close();
        is.close();

    }
    public static void imgController(Part inuptfile,String path,String filename)throws IOException{
        File filterpath = new File(path) ;
        if (!filterpath.exists()){
            filterpath.mkdir();
            log.info("11111"+filterpath);
        }//判断文件夹是否存在


        File file = new File(path,filename);

        if (!file.exists()){
            file.createNewFile();
            log.info("22222"+filterpath);
        }
        inputoutput(inuptfile,file);

    }
}
